package cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformconfig;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformconfig.PlatformConfigDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformconfig.vo.*;

/**
 * 跨境电商平台配置 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PlatformConfigMapper extends BaseMapperX<PlatformConfigDO> {

    default PageResult<PlatformConfigDO> selectPage(PlatformConfigPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PlatformConfigDO>()
                .eqIfPresent(PlatformConfigDO::getCode, reqVO.getCode())
                .likeIfPresent(PlatformConfigDO::getName, reqVO.getName())
                .eqIfPresent(PlatformConfigDO::getNameEn, reqVO.getNameEn())
                .eqIfPresent(PlatformConfigDO::getType, reqVO.getType())
                .eqIfPresent(PlatformConfigDO::getRegion, reqVO.getRegion())
                .eqIfPresent(PlatformConfigDO::getCountryCode, reqVO.getCountryCode())
                .eqIfPresent(PlatformConfigDO::getPlatformUrl, reqVO.getPlatformUrl())
                .eqIfPresent(PlatformConfigDO::getApiBaseUrl, reqVO.getApiBaseUrl())
                .eqIfPresent(PlatformConfigDO::getApiVersion, reqVO.getApiVersion())
                .eqIfPresent(PlatformConfigDO::getAuthType, reqVO.getAuthType())
                .eqIfPresent(PlatformConfigDO::getAuthConfig, reqVO.getAuthConfig())
                .eqIfPresent(PlatformConfigDO::getRateLimitConfig, reqVO.getRateLimitConfig())
                .eqIfPresent(PlatformConfigDO::getSupportedCurrencies, reqVO.getSupportedCurrencies())
                .eqIfPresent(PlatformConfigDO::getSupportedLanguages, reqVO.getSupportedLanguages())
                .eqIfPresent(PlatformConfigDO::getFeeConfig, reqVO.getFeeConfig())
                .eqIfPresent(PlatformConfigDO::getSyncConfig, reqVO.getSyncConfig())
                .eqIfPresent(PlatformConfigDO::getWebhookConfig, reqVO.getWebhookConfig())
                .eqIfPresent(PlatformConfigDO::getFeatures, reqVO.getFeatures())
                .eqIfPresent(PlatformConfigDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PlatformConfigDO::getEnabled, reqVO.getEnabled())
                .eqIfPresent(PlatformConfigDO::getSort, reqVO.getSort())
                .eqIfPresent(PlatformConfigDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PlatformConfigDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PlatformConfigDO::getId));
    }

    /**
     * 根据平台代码查询配置
     *
     * @param code 平台代码
     * @return 平台配置
     */
    default PlatformConfigDO selectByCode(String code) {
        return selectOne(PlatformConfigDO::getCode, code);
    }

}